package com.ruoyi.ade.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ade.service.IAdeAnalyzeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ade.domain.AdeLab;
import com.ruoyi.ade.service.IAdeLabService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AdeLabController
 * 
 * @author wxh
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/ade/lab")
public class AdeLabController extends BaseController
{
    @Autowired
    private IAdeLabService adeLabService;

    @Autowired
    private IAdeAnalyzeService adeAnalyzeService;

    @PutMapping("/execute/{id}")
    public AjaxResult execute(@PathVariable("id") Long id){
        try {
            adeAnalyzeService.execute(id);
            return AjaxResult.success();
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 查询AdeLab列表
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdeLab adeLab)
    {
        startPage();
        List<AdeLab> list = adeLabService.selectAdeLabList(adeLab);
        return getDataTable(list);
    }

    /**
     * 导出AdeLab列表
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:export')")
    @Log(title = "AdeLab", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdeLab adeLab)
    {
        List<AdeLab> list = adeLabService.selectAdeLabList(adeLab);
        ExcelUtil<AdeLab> util = new ExcelUtil<AdeLab>(AdeLab.class);
        util.exportExcel(response, list, "AdeLab数据");
    }

    /**
     * 获取AdeLab详细信息
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adeLabService.selectAdeLabById(id));
    }

    /**
     * 新增AdeLab
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:add')")
    @Log(title = "AdeLab", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdeLab adeLab)
    {
        adeLab.setCreateBy(getUsername());
        return toAjax(adeLabService.insertAdeLab(adeLab));
    }

    /**
     * 修改AdeLab
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:edit')")
    @Log(title = "AdeLab", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdeLab adeLab)
    {
        adeLab.setUpdateBy(getUsername());
        return toAjax(adeLabService.updateAdeLab(adeLab));
    }

    /**
     * 删除AdeLab
     */
    @PreAuthorize("@ss.hasPermi('ade:lab:remove')")
    @Log(title = "AdeLab", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adeLabService.deleteAdeLabByIds(ids));
    }
}
